package cn.afactory.tygz.ui.base.views.search;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.afactory.tygz.R;
import cn.afactory.tygz.ui.base.activities.SearchActivity;

/**
 * kenneth
 */
public class SearchNavigationView extends LinearLayout {
    private TextView mSearchTip;
    private OnSearchListener mListener;

    static {

    }

    private SearchSourcePager mSearchSourcePager = SearchSourcePager.TOPIC;

    public SearchNavigationView(Context context) {
        super(context);
        initView();
    }

    public SearchNavigationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public SearchNavigationView(Context context, AttributeSet attrs,
                                int defStyle) {
        super(context, attrs, defStyle);
        initView();
    }

    private void initView() {
        View view = inflate(getContext(), R.layout.view_search_nav_layout, this);
        mSearchTip = (TextView) view.findViewById(R.id.search_tip);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean handlerClick = false;
                if (mListener != null) {
                    handlerClick = mListener.onSearch();
                }
                if (!handlerClick) {
                    Intent intent = SearchActivity.createIntent(getContext(), mSearchSourcePager);
                    getContext().startActivity(intent);
                }
            }
        });

        //for topic search only
        setSearchTip("话题搜索");
    }

    /**
     * @param searchPage
     */
    public void setSearchSourcePager(SearchSourcePager searchPage) {
        mSearchSourcePager = searchPage;
        //for topic search only
        setSearchTip("话题搜索");
    }

    public void setOnSearchListener(OnSearchListener listener) {
        mListener = listener;
    }

    public interface OnSearchListener {
        /**
         * @return true表示自己处理跳转
         */
        boolean onSearch();
    }

    public void setSearchTip(String sTip) {
        if (!TextUtils.isEmpty(sTip)) {
            mSearchTip.setText(sTip);
        } else {

        }
    }
}
